<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<c:set var="buttons">
    <input type="button" style="margin-right: 5px"   onclick="f_add()" value="<fmt:message key="button.add"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_update()" value="<fmt:message key="button.update"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_delete()" value="<fmt:message key="button.delete"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_cancel()" value="<fmt:message key="button.cancel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_save()" value="<fmt:message key="button.save"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_query()" value="<fmt:message key="button.query"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_excel()" value="<fmt:message key="button.excel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_back()" value="<fmt:message key="button.back"/>"/>
</c:set>
<div id='toolbar' style="display:none">
<c:out value="${buttons}" escapeXml="false"/>
</div> 
<script>
Ext.onReady(globalScope._ready);
Ext.onReady(function(){
  var planType="<c:out value='${model.parameter.planType}'/>";
  if(planType=='teaching'){
    planType='教学安排';
  }else{
    planType='实践安排';
  }
  var directionName="<c:out value='${model.parameter.directionName}'/>";
  if(Ext.isEmpty(directionName)){
    directionName="";
  }else{
    directionName+="方向 ";
  }
  
  Ext.get('title').dom.innerHTML="<b><c:out value='${model.parameter.GRADE}'/>级 "+
                                 "<c:out value='${model.parameter.departmentName}'/> "+
                                 "<c:out value='${model.parameter.majorName}'/>专业 "+
                                 directionName+planType+"</b>";
   var tableName="<c:out value='${model.tableName}'/>";                                 
   var cnf=globalScope.form.get(tableName).getForm().findField("COURSE_NO");                                 
   var tcf=globalScope.form.get(tableName).getForm().findField("TEACH_COLLEGE");                                 
   var cnmf=globalScope.form.get(tableName).getForm().findField("COURSE_NAME");                                 
   var cf=globalScope.form.get(tableName).getForm().findField("CREDIT");                                 
   cnf.on('change',function(f,nv,ov){
      Ext.get(document.body).mask("查询课程信息");
      Ext.Ajax.request({
        method:'post',
        url:g_rootPath+'ajax/findCourseByNo.html',//
	    params:{courseNo:nv},
	    success:function(response){
	      Ext.get(document.body).unmask();
	      var resp=Ext.decode(response.responseText);
	       if(resp.success){
	         tcf.setValue(resp.course.teachCollege);
	         cnmf.setValue(resp.course.courseName);
	         cf.setValue(resp.course.credit);
	       }else{
	         f.setValue(ov);
	         Ext.Msg.alert('<fmt:message key="label.info"/>',resp.errorInfo);
	         
	       }
	    },
	    failure:function(){
	      Ext.get(document.body).unmask();
	    }
        
      });
   });
});



function f_back(){
   location=g_rootPath+'research/plan/major.html';
}
function f_excel(){
  globalScope._exportExcel();
//  globalScope._excel();
}

function f_add(tableName){
  globalScope._add(tableName);
}

function f_update(tableName){
  globalScope._update(tableName);
}

function f_delete(tableName){
  globalScope._delete(tableName);
} 

function f_cancel(tableName){
  globalScope._cancel(tableName);
}

function f_save(tableName,url){
  globalScope._save(tableName,url);
}

function f_query(tableName){
    globalScope._query(tableName);
}
function f_gotoPage(pageNo,rowsOfPage,pageCount,rowCount,conditoin){
  globalScope._gotoPage({spanName:"g_pageSpan_<c:out value='${model.tableName}'/>",pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:conditoin,tableName:"<c:out value='${model.tableName}'/>"},
                         {GRADE:'<c:out value='${model.parameter.GRADE}'/>',MAJOR:'<c:out value='${model.parameter.MAJOR}'/>',DIRECTION:'<c:out value='${model.parameter.DIRECTION}'/>'});
}
</script>
